﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using MM.Data.Entity;
using MM.Services.decl;

namespace MM.Services.impl
{
    public class JournalPaymentService : BaseService, IJournalPayment
    {
        public JournalPayment GetJournalPaymentById(int id)
        {
            return MyMoneyContext.JournalPayments.Find(id);
        }

        public void AddJournalPayment(JournalPayment journalPayment)
        {
            if (journalPayment != null)
            {
                MyMoneyContext.JournalPayments.Add(journalPayment);
            }
            Commit();
        }

        public List<JournalPayment> GetAllJournalPaymentsByDate(DateTime dateTime)
        {
            return (from jp in MyMoneyContext.JournalPayments
                    where EntityFunctions.TruncateTime(jp.DateTime) == dateTime.Date
                    select jp).ToList();
        }
    }
}